wheel.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from zipfile import ZipFile
  2. from pip._internal.distributions.base import AbstractDistribution
  3. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  4. from pip._internal.utils.wheel import pkg_resources_distribution_for_wheel
  5. if MYPY_CHECK_RUNNING:
  6. from pip._vendor.pkg_resources import Distribution
  7. from pip._internal.index.package_finder import PackageFinder
  8. class WheelDistribution(AbstractDistribution):
  9. """Represents a wheel distribution.
  10. This does not need any preparation as wheels can be directly unpacked.
  11. """
  12. def get_pkg_resources_distribution(self):
  13. # type: () -> Distribution
  14. """Loads the metadata from the wheel file into memory and returns a
  15. Distribution that uses it, not relying on the wheel file or
  16. requirement.
  17. """
  18. # Set as part of preparation during download.
  19. assert self.req.local_file_path
  20. # Wheels are never unnamed.
  21. assert self.req.name
  22. with ZipFile(self.req.local_file_path, allowZip64=True) as z:
  23. return pkg_resources_distribution_for_wheel(
  24. z, self.req.name, self.req.local_file_path
  25. )
  26. def prepare_distribution_metadata(self, finder, build_isolation):
  27. # type: (PackageFinder, bool) -> None
  28. pass